# -*- coding: utf-8 -*-
"""
 @Time    : 2021/2/22 下午3:58
 @Author  : tgy
 
"""
import struct




def test01():
    age = 20
    pack = struct.pack('i', age)
    print(pack)


def test02():
    '''
     struct{
        int age,
        double score,
        char name[10]
    }
    '''
    age = 20
    score = 91.1
    name = '张三'
    en_name = name.encode('utf-8')
    pack = struct.pack(f'id{len(en_name)}s',age,score,en_name)
    print(pack)
    p_name = struct.unpack(f'id{len(en_name)}s',pack)[-1]
    print(p_name.decode('utf-8'))



if __name__ == '__main__':
    ...
    test02()